package main

import (
	"fmt"
	"strings"
)

func main() {
	s := "i love  work and i love my family too"
	//按 指定字符截取，返回 slice
	s1 := strings.Split(s, " ")
	fmt.Println("s1=", s1) //	s1= [i love  work and i love my family too]
	//按 空格截取，返回 slice
	s2 := strings.Fields(s)
	fmt.Println("s2=", s2) //	s1= [i love  work and i love my family too]

	//判断是否存在某个字符或子串 返回bool
	flag := strings.Contains(s, "love")
	fmt.Println("flag=", flag) // flag = true

	//字符或者字符串在字符中第一次出现的位置,返回 下标,不存在返回 -1
	index := strings.Index(s, "love")
	fmt.Println("index =", index) //index = 2

	//字符或者字符串在字符中第一次出现的位置,返回 下标
	lastIndex := strings.LastIndex(s, "love")
	fmt.Println("lastIndex =", lastIndex) //lastIndex = 19

	//子串出现的次数
	count := strings.Count(s, "love")
	fmt.Println("count=", count) //count= 2

	//比较
	bs := strings.Compare("love", "Love")
	fmt.Println("bs=", bs) //bs= 1

	bs1 := strings.Compare("love", "love")
	fmt.Println("bs1=", bs1) //bs1= 0

	bs2 := strings.Compare("Love", "love")
	fmt.Println("bs2=", bs2) //bs2= -1

	//连接字符串
	join := strings.Join(strings.Fields(s), ",")

	fmt.Println("join=", join)

}
